//
//  userManageViewController.m
//  Umoney
//
//  Created by zwz on 16/8/2.
//  Copyright © 2016年 zhangwz. All rights reserved.
//

#import "userManageViewController.h"
#import "LoginViewController.h"
#import "CalculateViewController.h"
#import "chargeViewController.h"
#import "WithDrawViewController.h"
#import "MyFundListViewController.h"
#import "ProtocolDelegate.h"
#import "DangerViewController.h"

@interface userManageViewController ()<ProtocolDelegate>
{
    IBOutlet UIButton *SeeDetailButton;
    LoginViewController *_login;
    IBOutlet UILabel *MoneyTotal;
    IBOutlet UILabel *MoneyBalance;
    NSString *Username;
    NSString *UID;
    chargeViewController *charge;
    WithDrawViewController *withdraw;
    
}
@property (strong,nonatomic) NSString *TatolMoney;
@property (strong,nonatomic) NSString *BalanceMoney;

@end

@implementation userManageViewController

-(void)AfterCharge
{
    self.TatolMoney = charge.MoneyTotal;
    self.BalanceMoney = charge.MoneyBalance;
    float t = [self.TatolMoney floatValue];
    float b = [self.BalanceMoney floatValue];
    MoneyTotal.text = [NSString  stringWithFormat:@"%.2f",t];
    MoneyBalance.text = [NSString stringWithFormat:@"%.2f",b];
    
}

-(void)AfterWithdraw
{
    self.TatolMoney = withdraw.MoneyTotal;
    self.BalanceMoney = withdraw.MoneyBalance;
    float t = [self.TatolMoney floatValue];
    float b = [self.BalanceMoney floatValue];
    MoneyTotal.text = [NSString  stringWithFormat:@"%.2f",t];
    MoneyBalance.text = [NSString stringWithFormat:@"%.2f",b];

}

-(void)SetInfomation
{
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    UID = [user objectForKey:@"uid"];
    
    
    self.TatolMoney = _login.MoneyTotal;
    self.BalanceMoney = _login.MoneyBalance;
    Username = _login.Username;
    self.navigationItem.title = [NSString stringWithFormat:@"%@,你好",Username];
    
    float t = [self.TatolMoney floatValue];
    float b = [self.BalanceMoney floatValue];
    MoneyTotal.text = [NSString  stringWithFormat:@"%.2f",t];
    MoneyBalance.text = [NSString stringWithFormat:@"%.2f",b];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    MoneyTotal.textAlignment = NSTextAlignmentCenter;
    _login = [[LoginViewController alloc] init];
    [_login.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    [_login setDelegate:self];
    charge = [chargeViewController new];
    [charge setDelegate:self];
    withdraw = [[WithDrawViewController alloc] init];
    [withdraw setDelegate:self];
    
    self.navigationItem.title = @"---";
    self.TatolMoney = @"--.--";
    self.BalanceMoney = @"--.--";
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"退出登录" style:UIBarButtonItemStylePlain target:self action:@selector(DoLoginOut)];
    self.navigationItem.rightBarButtonItem.tintColor = [UIColor grayColor];
    
}

-(void)DoLoginOut
{
    _login.IsLogin= NO;
    [self presentViewController:_login animated:NO completion:nil];
}

- (IBAction)SeeDetailEvent:(id)sender
{
    if (SeeDetailButton.selected == NO) {
        [SeeDetailButton setBackgroundImage:[UIImage imageNamed:@"eye_closed.png"] forState:UIControlStateNormal];
        SeeDetailButton.selected =YES;
        //设置钱为＊＊＊＊
        MoneyTotal.text = @"* * * *";
        MoneyBalance.text = @"* * * *";
    }
    else
    {
        [SeeDetailButton setBackgroundImage:[UIImage imageNamed:@"eye_open.png"] forState:UIControlStateNormal];
        SeeDetailButton.selected = NO;
        float t = [self.TatolMoney floatValue];
        float b = [self.BalanceMoney floatValue];
        MoneyTotal.text = [NSString  stringWithFormat:@"%.2f",t];
        MoneyBalance.text = [NSString stringWithFormat:@"%.2f",b];
    }
}

- (IBAction)DoChargeEvent:(id)sender {
    //充值
    charge.Balance.text = MoneyBalance.text;
    [self.navigationController pushViewController:charge animated:YES];
    
}

- (IBAction)DoWithdrawEvent:(id)sender {
    //提现
    withdraw.Balance.text = MoneyBalance.text;
    [self.navigationController pushViewController:withdraw animated:YES];
}

- (IBAction)CheckCalculate:(id)sender {
    CalculateViewController *calac = [CalculateViewController new];
    [self.navigationController pushViewController:calac animated:YES];
}

- (IBAction)CheckMyFund:(id)sender {
    MyFundListViewController *myfundlist = [[MyFundListViewController alloc] init];
    [self.navigationController pushViewController:myfundlist animated:YES];
}


-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    _login.modalTransitionStyle=UIModalTransitionStyleCoverVertical;
    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"firstStart"]) {
        NSLog(@"第一次");
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstStart"];//设置成yes以后再也不进入
        //进入引导页;进入注册界面；
        [self presentViewController:_login animated:YES completion:^{
            dispatch_after(100, dispatch_get_main_queue(), ^{
                [self dismissViewControllerAnimated:YES completion:nil];
            });
        }];
    }else{
        NSLog(@"不是第一次");
        //判断是否登入，进入登入界面；
        if (_login.IsLogin == YES) {

        }
        else
        {
            [self presentViewController:_login animated:YES completion:nil];
        }
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
